<?php namespace Common\Model;
use Hdphp\Model\Model;
//期数操作模型
class Periods extends Model{
	
	protected $table = "goods_periods";
	//自动验证
	protected $validate = array(
		array('periods','required','商品期数不能为空',3,3),
	);
	//自动完成
	protected $auto = array(
		array('start_time','time','function',3,1),
	);
	
	//添加
	public function addData(){
		//验证
		if(!$this->create()) return false;
		//因为多个商品同时添加同一期，good_gid是一个数组所以要循环它，里面重组数组并添加
		foreach (Q('post.goods_gid',array()) as $k => $v) {
			$data = array(
				'periods'=>Q('post.periods'),
				'goods_gid'=>$v,
				'start_time'=>time(),
			);
			$this->add($data);
		}
		return true;
		
	}
	
	//删除某一商品的期数
	public function realDel($gpid){
		$this->where("gpid={$gpid}")->delete();
	}
}





 ?>